package org.pearl.thread.demo.test001;

/**
 * Created by TD on 2021/4/11
 */
public class ThreadStatusTest002 {
    public static void main(String[] args) {
        Object obj = new Object();
        // 创建一个执行线程
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj) {
                    System.out.println(Thread.currentThread().getName() + " is running..."); // t1
                    try {
                        //  Object.wait进入无限等待
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t1.start();
        // 创建一个执行线程 唤醒其他线程
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj) {
                    System.out.println(Thread.currentThread().getName() + " is running..." ); // t1
                    //
                    obj.notify();
                    // obj.notifyAll();
                }
            }
        });
        t2.start();
        System.out.println(Thread.currentThread().getName() + " is running..."); //main
    }
}
